{% extends "template/listEdit.volt" %}

{% block title %}我的任务{% endblock %}


{% block filter %}
    <div class="col-md-4 col-sm-6 col-xs-12">
        <table>
            <tr>
                <th>ID:</th>
                <td><input type="text" name="id" value=""></td>
            </tr>

        </table>
    </div>
    <div class="col-md-4 col-sm-6 col-xs-12">
        <table>
            <tr>
                <th>状态:</th>
                <td><select name="status">
                        <option value="">请选择</option>
                        <option value="0">待处理</option>
                        <option value="1">已接受</option>
                        <option value="2">已拒绝</option>
                    </select></td>
            </tr>
        </table>
    </div>
    <div class="col-md-4 col-sm-6 col-xs-12">
        <table>
            <tr>
                <th>分派时间:</th>
                <td><input type="date-h" name="created_at_start" data-attr="date" id="flight-date-start"
                           value="">-<input type="date-h" name="created_at_end" data-attr="date right" class="end"
                                            value=""></td>
            </tr>
            <tr>
                <td colspan="2">
                    <div id="btn_reset_param" class="btn-0 button">重 置</div>
                    <div id="btn_search_data" class="btn-1 button">过 滤</div>
                </td>
            </tr>
        </table>
    </div>
    <div style="display: none">
        <div id="curUser">{{ curUser }}</div>
    </div>
{% endblock %}

{% block hiddenOperation %}hidden{% endblock %}

{% block jscontent %}

    <script>

        var global_cur_user = eval("(" + $("#curUser").text() + ")");
        function clickAcceptAction(id, typeVal) {
            loadingView.show();
            feimaPost("/task/acceptAssign", {
                "id": id,
                "type": typeVal
            }, function (result) {
                loadingView.remove();
                FAlert(result.message);
                PageDataProxy.refresh();
            });

        }
        function clickRejectAction(id) {
            loadingView.show();
            feimaPost("/task/deny", {
                "id": id
            }, function (result) {
                loadingView.remove();
                FAlert(result.message);
                PageDataProxy.refresh();
            });
        }

        var curAssignId = 0;

        function getStatusColor(statusId) {
            if (statusId == "已接收") {
                return "#3CD814";
            }
            if (statusId == "已拒绝") {
                return "#FC4E4E";
            }
            if (statusId == "待处理") {
                return "#FFF700";
            }


        }
        function clickShowMessageWindow(index) {
            loadingView.show();
            var data = PageDataProxy.currentData["data"][index];

            var taskName = data["project_name"];
            var status = data["status"];
            var taskId = data["id"];
            var created_at = data["created_at"];
            curAssignId = taskId;
            // 备注聊天信息
            var commentData = {
                missionName: taskName,
                dispatchTime: created_at,
                stateColor: getStatusColor(status),
                stateName: status,

            };
            commentChatM.show(commentData, function (toSendData) {
                commentChatM.sendBtnEnable(false);
                console.log(toSendData);
                feimaPost("/task/reply", {
                    "id": curAssignId,
                    "message": toSendData
                }, function (result) {
                    commentChatM.sendBtnEnable(true);
                    if (result.status == 0) {
                        var date = new Date();
                        commentChatM.clearInput();

                        commentChatM.appendMsgs([{
                            time: date.Format("yyyy-MM-dd hh-mm"),
                            icon: global_cur_user.iconUrl ? global_cur_user.iconUrl : "/images/main/main_user_icon.png",
                            name: global_cur_user.name,
                            content: toSendData,
                            isLeft: false,
                        }]);
                    }
                });
            });

            feimaPost("/task/replyList", {
                "id": taskId
            }, function (result) {
                loadingView.remove();
                if (result.status == 0) {

                    if (result.data) {
                        var array = new Array();
                        for (var i = 0; i < result.data.length; i++) {
                            var item = result.data[i];
                            var isLeft = true;
                            if (item["user_id"] == global_cur_user["userId"]) {
                                isLeft = false;
                            }
                            array.push(
                                    {
                                        "time": item["created_at"],
                                        "icon": item["icon_url"] ? item["icon_url"] : "/images/main/main_user_icon.png",
                                        "content": item["info"],
                                        "isLeft": isLeft,
                                        "name": item["nickname"]
                                    }
                            )
                        }
                        commentChatM.appendMsgs(array);
                    }

                }
            });
        }

        $(function () {
            PageDataProxy.init({
                "url": "/task/listMy",
                "table_id": "#mytable",
                "page_control_id": "#data-wrap",
                "page_size_id": "#rows-perpage-select",
                "page_total_id": "#data_count_total",
                "use_check_box": false,
                "data_field_process": function (name, value) {
                    if(name=='status'){
                        if (value == 0) {
                            value = "<span style='font-weight:bold; color:#ffffff; background: #dbd616; border-radius:4px'>&nbsp;待处理&nbsp;</span>";
                        }
                        if (value == 2) {
                            value = "<span style='font-weight:bold; color:#ffffff; background: #00db1c; border-radius:4px'>&nbsp;已接受&nbsp;</span>";
                        }
                        if (value == 3) {
                            value = "<span style='font-weight:bold; color:#ffffff; background: #db0006; border-radius:4px'>&nbsp;已拒绝&nbsp;</span>";
                        }
                    }
                    return value;
                },

                "table_style": {
                    "project_name": "width-b",
                    "status": "width-s",
                    "created_at": "width-m",
                },
                "data_field_on_line_process": function (index, data) {
                    return "<td class='width-s' onclick='clickShowMessageWindow(" + index + ")'><img src='/images/dispatch-mission-comment-hl.png' /></td>";
                },
                "data_head_on_line_process": function () {

                    return "<th class='width-s'>消息</th>";
                },
                "operation_style": "width: 300px; min-width: 300px;",
                "data_field_action_process": function (tag, index, data) {
                    var item = data["data"][index];
                    var id = item["id"];
                    if (item["status"] == "待处理") {
                        var str = "<td onclick='clickAcceptAction(" + id + ",0)'><img class='action-accept-icon'>接受</td>";
                        str += "<td onclick='clickAcceptAction(" + id + ",1)'><img class='action-save-as-icon'>覆盖</td>";
                        str += "<td onclick='clickAcceptAction(" + id + ",2)'><img class='action-cover-icon'>另存</td>";
                        str += "<td onclick='clickRejectAction(" + id + ")'><img class='action-refuse-icon'>拒绝</td>";
                        return str;
                    } else {
                        return "";
                    }
                },

            });


        })
    </script>
{% endblock %}